package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueRegulationDao;
import com.prs.crm.domain.doc.IssueRegulation;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Regulation;
import com.prs.crm.service.doc.IssueRegulationService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.RegulationService;

public class IssueRegulationServiceImpl extends BaseServiceImpl<IssueRegulation,IssueRegulationDao> implements IssueRegulationService{
	private PersonService personService;
	private RegulationService regulationService; 
	
	@Override
	public void submitIssueRegulation(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Regulation> regulations = this.getRegulationService().getRegulationByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		
		for(Person person : persons) {
			for(Regulation regulation : regulations) {
				IssueRegulation issue = new IssueRegulation();
				issue.setRegulation(regulation);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setRegulationService(RegulationService regulationService) {
		this.regulationService = regulationService;
	}

	public RegulationService getRegulationService() {
		return regulationService;
	}

	@Override
	public Collection<IssueRegulation> getValidIssueRegulation(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueRegulation(person);
	}

}
